<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<script type="application/x-javascript" src="http://mashmaker.intel.com/v18/mashmaker_api.js"></script>
<script type="text/javascript" src="http://mashmaker.intel.com/v18/mashmaker_util.js"></script>
<script type="text/javascript" src="http://mashmaker.intel.com/v18/mashmaker_settings.js"></script>
<script type="text/javascript" src="http://mashmaker.intel.com/v18/mashmaker_patterns.js"></script>
<script type="text/javascript" src="http://www.krillion.com/static/js/availability.js"></script>
<link rel="stylesheet" href="http://mashmaker.intel.com/v18/mashprops.css"/>
<script type="application/x-javascript">
// <![CDATA[
// BEGIN: Cookie Utility Functions
// Returns null or unescaped cookie value
function get_cookie ( name ) {
  var results = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' );
  if ( results ) return ( unescape( results[2] ) );
  else return null;
}
// Set cookie value, expiration date is optional.
function set_cookie ( name, value, exp_year, exp_month, exp_day) {
  var cookie_string = name + "=" + escape( value );
  if ( exp_year ) {
    var expires = new Date ( exp_year, exp_month, exp_day );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  document.cookie = cookie_string;
}
// END: Cookie Utility Functions

var global_done = {}

function init(){
    var opts = {
        path : false,
        slots : ["name"],
        setItems : set_items,
        guess : guess_settings
    };
    mashmaker_patterns.itemsByProp.widget(opts);
}

function guess_settings() {
    global_settings = {};

    // Either retrieve default zip from cookie *or* set our initial default
    var zip_default = get_cookie( "krillion-stockcheck-zip");
    if ( !zip_default ) zip_default = "94041";
    global_settings.zip = zip_default;

    mashmaker_patterns.itemsByProp.guess_settings();
}

var k_account = "AB4D2DA1-0380-4843-907E-C412765FD6DD";
var k_brand;
var k_sku;

function set_items(itemList) {
    k_brand = null;
    k_sku = null;
    if (  itemList.length > 0
       && itemList[0].slots.name) {
        var name = itemList[0].slots.name[0];
        if (name != null) {
            var words = new Array();
            words = name.split(" ");
            if (words.length >= 2) {
                k_brand = words[0];
                var digitRegEx = /[0-9]+/;
                for (var i=1; i<words.length; i++) {
                    if (words[i].search(digitRegEx) >= 0) {
                        k_sku = words[i];
                        break;
                    }
                }
            }
        }
    }

    if (k_brand && k_sku) {
        verifyKrillionProductAvailability(k_account, k_brand, k_sku, showResultsCallback);
    } else {
        var resDiv = document.getElementById("krillion_results");
        resDiv.innerHTML = "<h3 align='center' style='color:#cd3333'>Product Name Not Found On Web Page</h3>";
        mashmaker.done();
    }
}

function showResultsCallback(haveResults) {
    if (haveResults == "true") {
        showKrillionAvailabilityResults(k_account, "krillion_results",
            window.innerWidth, window.innerHeight,
            global_settings.zip, k_brand, k_sku, true);
    } else {
        var resDiv = document.getElementById("krillion_results");
        resDiv.innerHTML = "<h3 align='center' style='color:#cd3333'>No Results for "
                + k_brand + " " + k_sku + "</h3>";
    }

    mashmaker.done();
}

function resize_widget() {
    var resDiv = document.getElementById("krillion_results");
    for (var i = 0; i < resDiv.childNodes.length; i++) {
        var child = resDiv.childNodes[i];
        if (child.tagName == "IFRAME") {
            child.setAttribute("width", window.innerWidth);
            child.setAttribute("height", window.innerHeight);
        }
    }
}

function process_onload() {
    window.addEventListener("resize", resize_widget, false);
    init();
}
// ]]>
</script>
</head>

<body style="margin:0px; padding-left: 5px">
<div id="krillion_results">&nbsp;</div>
<script type="application/x-javascript">process_onload();</script>
</body>

</html>